﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BL.BetterControls
{
    [Serializable]
    public enum _ZurbButtonType
    {
        none, normal, function, negative, positive, normal_small, function_small, negative_small, positive_small
                
    }

    [ToolboxData("<{0}:_Button Description=\"\" DivStyle=\"\"  DivType=\"none\" ZurbType=\"none\" runat=\"server\"></{0}:_Button>")]
    public class _Button : Button
    {
        public _DivType DivType { get { return ViewState["DivType"] != null ? (_DivType)Enum.Parse(typeof(_DivType),ViewState["DivType"].ToString()) : _DivType.none; }  set { ViewState["DivType"] = value.ToString(); } }
        public string DivStyle { get { return ViewState["DivStyle"] != null ? (string)ViewState["DivStyle"] : ""; } set { ViewState["DivStyle"] = value; } }
        public string Description { get { return this.Text; } set { this.Text = value; } }
        /// <summary>
        /// adds some zurb classes by type
        /// normal, function, negative, positive
        /// </summary>

        public _ZurbButtonType ZurbType { 
            get { return ViewState["ZurbType"] != null ? (_ZurbButtonType)Enum.Parse(typeof(_ZurbButtonType), ViewState["ZurbType"].ToString()) : _ZurbButtonType.normal; } 
            set { ViewState["ZurbType"] = value.ToString(); } }

        

        protected override void Render(HtmlTextWriter writer)
        {

            if (this.ToolTip == "")
                this.ToolTip = this.Description;

            if (DivType != _DivType.none)
            {
                writer.Write("<div");
                
                writer.Write(" class=\"" + DivType.ToString() + "\"");
                if (DivStyle != string.Empty)
                    writer.Write(" style=\"" + DivStyle + "\"");

                writer.Write(">");

            }
           

            if (ZurbType != _ZurbButtonType.none)
            {
                if (ZurbType == _ZurbButtonType.normal_small)
                {
                    CssClass += " small radius button";
                }
                else if (ZurbType == _ZurbButtonType.function_small)
                {
                    CssClass += " small radius secondary button";
                }
                else if (ZurbType == _ZurbButtonType.negative_small)
                {
                    CssClass += " small radius alert button";
                }
                else if (ZurbType == _ZurbButtonType.positive_small)
                {
                    CssClass += " small radius success button";
                }

                if (ZurbType == _ZurbButtonType.normal)
                {
                    CssClass += " radius button";
                }
                else if (ZurbType == _ZurbButtonType.function)
                {
                    CssClass += " radius secondary button";
                }
                else if (ZurbType == _ZurbButtonType.negative)
                {
                    CssClass += " radius alert button";
                }
                else if (ZurbType == _ZurbButtonType.positive)
                {
                    CssClass += " radius success button";
                }
            }

            if (!CssClass.Contains("button"))
            {
                if (CssClass.Length > 0)
                    CssClass = CssClass + " button";
                else
                    CssClass = "button";
            }


            base.Render(writer);


            if (DivType != _DivType.none)
                writer.Write("</div>"); ;
        }
    }
}
